package com.lkd.job;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lkd.common.VMSystem;
import com.lkd.entity.VendingMachineEntity;
import com.lkd.service.VendingMachineService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.log.XxlJobLogger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
@Slf4j
public class SupplyJob {
    @Autowired
    private VendingMachineService vmService;


    /**
     * 售货机扫描，然后调用方法，发送补货任务；
     * @param param
     * @return
     */
    public ReturnT<String> supplyJobHandler(String param){
        //1.查询运营中的售货机
        LambdaQueryWrapper<VendingMachineEntity>qw=new LambdaQueryWrapper<>();
        qw.eq(VendingMachineEntity::getVmStatus, VMSystem.VM_STATUS_RUNNING);
        List<VendingMachineEntity> vmList = vmService.list(qw);
        vmList.forEach(vm->{
            XxlJobLogger.log("扫描售货机："+vm.getInnerCode());
            vmService.sendSupplyTask(vm.getInnerCode());
        });
        return ReturnT.SUCCESS;
    }

}
